package com.wd.health.model.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;
import com.wd.health.model.bean.HistoryMoneyBean;

import java.text.SimpleDateFormat;
import java.util.List;


public class HistoryMoneyAdaptor extends RecyclerView.Adapter<HistoryMoneyAdaptor.Holder> {
    private List<HistoryMoneyBean.ResultBean> consume_list;
    SimpleDateFormat aDate = new SimpleDateFormat("yyyy-MM-dd  HH:mm");

    public HistoryMoneyAdaptor(List<HistoryMoneyBean.ResultBean> result) {
        this.consume_list = result;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_historymoney,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        int type = consume_list.get(position).getType();
        int direction = consume_list.get(position).getDirection();
        String format = aDate.format(consume_list.get(position).getCreateTime());
        if (type==1){//签到
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("签到");
            holder.consume_time.setText(format);
        }else if (type==2){//朋友圈评论首发
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("病友圈首评");
            holder.consume_time.setText(format);
        }else if (type==3){//朋友圈评论首评
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("首发病友圈");
            holder.consume_time.setText(format);
        }else if (type==4){//完善档案
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("完善档案");
            holder.consume_time.setText(format);
        }else if (type==5){//健康测评
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("健康评测");
            holder.consume_time.setText(format);
        }else if (type==6){//悬赏消费
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("悬赏消费");
            holder.consume_time.setText(format);
        }else if (type==7){//朋友圈评论首评
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("悬赏奖励");
            holder.consume_time.setText(format);
        }else if (type==8){//邀请奖励
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("邀请奖励");
            holder.consume_time.setText(format);
        }else if (type==9){//问诊消费
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("问诊消费");
            holder.consume_time.setText(format);
        }else if (type==10){//问诊收入
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("问诊收入");
            holder.consume_time.setText(format);
        }else if (type==11){//观看咨询
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("观看资讯");
            holder.consume_time.setText(format);
        }else if (type==12){//送礼物
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("送礼物");
            holder.consume_time.setText(format);
        }else if (type==13){//绑定身份证
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("绑定身份证");
            holder.consume_time.setText(format);
        }else if (type==14){//绑定银行卡
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("绑定银行卡");
            holder.consume_time.setText(format);
        }else if (type==15){//充值
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("充值");
            holder.consume_time.setText(format);
        }else if (type==16){//体现
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("提现");
            holder.consume_time.setText(format);
        }else if (type==17){//购买健康视频
            if (direction==1){//收入
                holder.consume_num.setText("+"+consume_list.get(position).getChangeNum()+"H币");
                holder.consume_num.setTextColor(Color.RED);
            } else if (direction==2) {//支出
                holder.consume_num.setText(consume_list.get(position).getChangeNum()+"H币");
            }
            holder.consume_name.setText("购买健康视频");
            holder.consume_time.setText(format);
        }

    }

    @Override
    public int getItemCount() {
        return consume_list == null ?0 : consume_list.size();
    }

    public class Holder extends RecyclerView.ViewHolder {
        TextView consume_name;
        TextView consume_time;
        TextView consume_num;
        public Holder(@NonNull View itemView) {
            super(itemView);
            consume_name = itemView.findViewById(R.id.consume_name);
            consume_time = itemView.findViewById(R.id.consume_time);
            consume_num = itemView.findViewById(R.id.consume_num);
        }
    }
}
